<template>
	<view>
	<view class="formdiv" v-if="!isru">
	  <view class="showtips">您好，“{{nickname}}”邀请您成为新的网点</view>
	  <view class="padd">
	    <view class="uploadbtn" @click="uploadfile">请上传营业执照</view>
	  </view>
	  <view class="itemcent">
	      <view class="leftname">营业执照</view>
	      <view class="riginput"><input type="text"   
	        v-model="netname"
	        disabled="disabled"
	        placeholder="营业执照名称" /></view>
	  </view>
	  <view class="itemcent">
	      <view class="leftname">网点名称</view>
	      <view class="riginput"><input type="text"   
	        v-model="netname2"
	        placeholder="网点名称" /></view>
	  </view>
	 
	  <view class="itemcent">
	      <view class="leftname">营业执照</view>
	      <view class="riginput"><input 
	        v-model="ying_ye_zhi_zao"
	        disabled="disabled"
	      type="text" placeholder="营业执照编号" /></view>
	  </view>
	
	  <view class="itemcent">
	      <view class="leftname">营业地址</view>
	      <view class="riginput">
	      <input type="text" 
	      v-model="netaddr"
	      disabled="disabled"
	      placeholder="营业地址" /></view>
	  </view>
	
	  <view class="itemcent">
	      <view class="leftname">手机号码</view>
	      <view class="riginput">
	      <input type="text"
	      v-model="bossphone" 
	      placeholder="请输入手机号码" /></view>
	  </view>
	  <view class="itemcent">
	      <view class="leftname">网点地址</view>
	      <view class="riginput">
	      <input type="text"
	      v-model="address" 
		  @click="get_map_address"
	      placeholder="请输入网点地址" /></view>
	  </view>
	  <view class="tipss">
	     注：手机号码将作为您的登录账号来使用
	  </view>
	
	  <view class="itemcent" style="height: auto;display:none;">
	      <view class="leftname">经营品项</view>
	      <view class="riginput">
	            <block v-if="product">
	              <view class="colortext" bind:tap="openjypnx">{{product}}</view>
	            </block>
	            <block v-if="product == ''">
	                <view class="colortext">
	                  <input type="text" disabled="disabled" @click="openjypnx"  placeholder="请选择经营品项"  />
	                </view>
	            </block>
	      </view>
	  </view>
	  <view class="savebtn" @click="savewdinfo">提交信息</view>
	</view>
	
	<view class="popup-box" v-if="showIndex=='2'" @click="closePopup"></view> 
	
	<view v-if="isru" class="showrentip">
	    <view>您已认证了，请勿重复认证！</view>
	    <view class="lokkdd" bind:tap="gotologin">查看我的门店</view>
	</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				  productlist:[],//经营品项列表
				  ying_ye_zhi_zao:"",//营业执照
				  netname:"",//营业执照名称
				  netname2:"",//网点名称
				  bossphone:"", //手机号
				  netaddr:"", //网点地址
				  showIndex:0,
				  yyzz_pic:"",//营业执照图片
				  items: [],
				  address:"",//选择地图上面的网点地址
				  nickname:"",
				  isru:0,//是否可以提交信息
				  netcode:"",
				  jxs_code:"",
				  latitude:"",
				  longitude:"",
				  province:"",
				  city:"",
				  district:"",
				  detail:"",
				  product:"", //经营品项名称
				  product_code:"" //经营品项编号
			}
		},
		onShow() {
			
		},
		onLoad(p) {
			this.nickname=p.nickname
			this.jxs_code=p.jxs_code
		},
		methods: {
			getAddress: function() {
				var n = this;
				uni.getLocation({
					type: 'wgs84',
					success: function(e) {
						var d={}
						n.latitude=e.latitude
						n.longitude=e.longitude
						
					},
					fail: (res) => {
						
					}
				});
			},
			uploadfile(){
			      var data={}
			      var that = this;
				  var token=uni.getStorageSync("fahuo_jxs_token");
				  var header = { 'content-type': 'multipart/form-data'};
				  if(token){
				  	header.token=token
				  }
			      uni.chooseImage({
					  count: 1,
					  sizeType: ['original', 'compressed'],
					  sourceType: ['album', 'camera'],
					  success: (chooseImageRes) => {
						const tempFilePaths = chooseImageRes.tempFilePaths;
						uni.uploadFile({
						  url:'https://myr.wissun.net/api/code/xklb_upload',
						  filePath: tempFilePaths[0],
						  name: 'image',
						  header:header,
						  success: (uploadFileRes) => {
							uploadFileRes=JSON.parse(uploadFileRes.data)
							that.shibieyyzz(uploadFileRes.info.url)
						  },
						  fail:(res) => {
						  	console.log('fail',res)
						  }
						});
					  },
					  fail: (chooseImageErr) => {
						console.error('choose image fail:', chooseImageErr);
					  }
				});
			},
			get_map_address(){
				var n=this
				uni.chooseLocation({
					success:function(res){
						if (res.errMsg === 'chooseLocation:ok') {
							  console.log("res",res)
							  console.log('位置名称：' + res.name);
							  console.log('详细地址：' + res.address);
							  console.log('纬度：' + res.latitude);
							  console.log('经度：' + res.longitude);
							  n.latitude=res.latitude
							  n.longitude=res.longitude
							  n.address=res.name
							  var d={}
							  d.latitude=n.latitude
							  d.longitude=n.longitude
							  n.request('/api/code/get_city', d,"post").then(ret => {
								n.detail=ret.info.result.address
							  	n.city=ret.info.result.address_component.city
							  	n.province=ret.info.result.address_component.province
								n.district=ret.info.result.address_component.district
							  	n.nation=ret.info.result.address_component.nation
							  })
						}
					}
				})
			},
			//识别营业执照方法
			shibieyyzz(pic){
			  var that=this
			  uni.showLoading({ title: '识别中,请稍后...'})
			  this.request('/api/code/shibie_yyzz', {pic:pic},"post").then(rt => {
				uni.hideLoading()
				var body=rt.data.body.Data
				body=JSON.parse(body)
				console.log("body",body)
				if(body.data.companyName==""){
				  body.data.companyName="暂无";
				}
				that.yyzz_pic=pic
				that.netname=body.data.companyName
				that.netname2=body.data.companyName
				that.ying_ye_zhi_zao=body.data.creditCode
				that.netaddr=body.data.businessAddress
			  })
			},
			 //保存信息
			savewdinfo(){
			  var data={}
			  let that=this
			  if(that.netname == ""){
				uni.showToast({  title: '请上传营业执照', icon:"none" })
				return
			  }
			  if(that.netname2 == ""){
				uni.showToast({  title: '请填写网点名称', icon:"none" })
				return
			  }
			  if(that.ying_ye_zhi_zao == ""){
				uni.showToast({  title: '请上传营业执照',icon:"none"})
				return
			  }
			  if(that.netaddr == ""){
				uni.showToast({  title: '请上传营业执照', icon:"none"})
				return
			  }
			  if(that.bossphone == ""){
				uni.showToast({ title: '请输入手机号码', icon:"none"})
				return
			  }
			  let product=[];
			  let items = this.productlist
			  for(var i=0;i<items.length;i++){
				if (items[i].checked) {  product.push(items[i].tc_qss04) }
			  }
			  data.ying_ye_zhi_zao=that.ying_ye_zhi_zao //营业执照
			  data.netname=that.netname //网点名称
			  data.netname2=that.netname2
			  data.bossphone=that.bossphone //手机号
			  data.netaddr=that.netaddr  //网点地址
			  data.product=product.join(",") //经营品项
			  data.openid=uni.getStorageSync('openid') //小程序标识
			  data.nickname=that.nickname
			  data.jxs_code=that.jxs_code
			  data.yyzz_pic=that.yyzz_pic
			  data.netcode=that.netcode //网点编号
			  
			  data.detail=that.detail
			  data.city=that.city
			  data.province=that.province
			  data.district=that.district
			  data.latitude=that.latitude
			  data.longitude=that.longitude
			  
			  uni.showLoading({ title: '提交中,请稍等'})
			  this.request('/api/code/save_wd_info', data,"post").then(rt => {
				  uni.hideLoading()
				  uni.showToast({
				  	title:"提交成功",
					icon:"none"
				  })
				  setTimeout(function(){
					  uni.redirectTo({
					  	url:"/pages/main/duojifahuo/wdzhaomu/setp3"
					  })
				  },2000)
			  })
			},
		}
	}
</script>

<style>
.uploadbtn{
  width: 150px;
  text-align: center;
  margin: 0 auto;
  background-color: #1B764A;
  color: #fff;
  height: 35px;
  line-height: 35px;
  border-radius: 5px;
  font-size: 14px;
  margin-bottom: 20px;
}
.showrentip{
  text-align: center;
  margin-top: 150px;
}
.lokkdd{
  
  border: 1px solid #1B764A;
  color: #1B764A;
  width: 100px;
  height: 30px;
  line-height: 30px;
  margin: 0 auto;
  margin-top: 40px;
  border-radius: 5px;
  font-size: 14px;
}
.showtips{
  margin: 10px;
  font-size: 14px;
  padding: 10px;
  color: #999;
}
.tipss{
  font-size: 14px;
  color: #999;
  padding-left: 10px;
}
.itemcent{
  display: flex;
  height: 35px;
  line-height: 35px;
  background: #fff;
  padding-left: 10px;
  font-size: 14px;
  border-bottom: 2px solid #eee;
  width: calc(100% - 40px);
  margin: 0 auto;
  margin: 10px;
}
.leftname{
  width: 80px;
}
.riginput{
  width: calc(100% - 80px);
}
.riginput input{
  height: 35px;
  line-height: 35px;
  width: 100%;
}
page{
  background-color: #eee;
}
.formdiv{
  width: calc(100% - 20px);
  margin: 30px auto;
  background-color: #fff;
  border-radius: 2px;
  padding-bottom: 50px;
}
.savebtn{
  background-color: #1B764A;
  color: #fff;
  width: 150px;
  text-align: center;
  margin: 0 auto;
  height: 35px;
  line-height: 35px;
  border-radius: 5px;
  font-size: 14px;
  margin-top: 50px;
}

/* 蒙层 */
.popup-box{
  position: absolute;
  z-index: 99;
  top: 0;
  background-color: rgba(0, 0, 0, 0.5);
  width: 100%;
  height: 100%;
}
/* 上 */
.info-top{
  position: fixed;
  z-index: 999;
  width: 100%;
  top: 0;
  background-color: white;
  border-bottom-left-radius: 5rpx;
  border-bottom-right-radius: 5rpx;
}
/* 中 */
.info-center{
  position: fixed;
  z-index: 999;
  background-color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10rpx;
  width: 90%;
  margin-left: 5%;
  margin-right: 5%;
}
/* 下 */
.info-bottom{
  position: fixed;
  z-index: 999;
  width: 100%;
  bottom: 0;
  background-color: white;
  border-top-left-radius: 10rpx;
  border-top-right-radius: 10rpx;
}
/* 左 */
.info-left{
  position: fixed;
  z-index: 999;
  width: 50%;
  height: 100%;
  top: 0;
  background-color: white;
  border-top-right-radius: 10rpx;
  border-bottom-right-radius: 10rpx;
}
/* 右 */
.info-right{
  position: fixed;
  z-index: 999;
  width: 50%;
  height: 100%;
  right: 0;
  top: 0;
  background-color: white;
  border-top-left-radius: 10rpx;
  border-bottom-left-radius: 10rpx;
}
/* 自定义内容（根据自己需求更改,可删除） */
button{
  margin: 15rpx 0;
}
.row-info{
  display: flex;
  flex-direction: column;
  align-items: center;
  margin: 15rpx;
  font-size: 32rpx;
}
.row-info view{
  padding: 10rpx 0;
}
.row-info view:first-child{
  display: flex;
  flex-direction: row;
  align-items: center;
}
.line{
  width: 100rpx;
  height: 1rpx;
}
.left-line{
  background-image: linear-gradient(to left,orange,white);
}
.right-line{
  background-image: linear-gradient(to right,orange,white);
}
.row-author{
  font-size: 24rpx;
  color: gray;
}
.row-btn{
  display: flex;
  flex-direction: row;
  align-items: center;
  border-top: 1rpx dashed #f1f1f1;
}
.row-btn view{
  flex: 1;
  text-align: center;
  margin: 20rpx 10%;
  padding: 12rpx 0;
  font-size: 32rpx;
  border-radius: 10rpx;
}
.left-btn{
  background-color: #f1f1f1;
  color: #33ccff;
}
.right-btn{
  background-color: #33ccff;
  color: white;
}
.fixed{
  position: fixed;
  bottom: 0;
  width: 50%;
}
.padd{padding-top: 30px;}

</style>
